#include "com.h"

int main()
{
  umask(0);
  int fd = open(FILE_NAME, O_RDONLY);
  if(fd < 0){
    perror("read");
    return 1;
  }

 int outfd = open("tmp.txt", O_WRONLY | O_CREAT, 0644); 
 if(outfd < 0){
   perror("open");
   return 1;
 }

 char* msg[128];
 while(1){
   ssize_t s = read(fd, msg, sizeof(msg));
   if(s == sizeof(msg)){
      write(outfd, msg, s);
   }
   else if(s < sizeof(msg)){
     write(outfd, msg, s);
     printf("read file end\n");
     break;
   }
   else{
     perror("read");
     break;
   }
 }

  close(fd);
  close(outfd);
  return 0;
}
